/**
 * 
 */
$(function(){
	VehicleMenu.init();
});

var mDialogCallback;
var mDialogOkCall;
var mFrameName;
var mDialogSaveCall;

var VehicleMenu = {
	init : function(){
		this.menu();
		this.initEvent();
	},
	initEvent: function(){
		//确定按钮事件
 		$("#confirmOK").click(function() {
            $('#confirmModal').modal('hide');
	    	onCallBack(mFrameName,mDialogCallback);
        });
 		 		
 		$("#btnSaveOK").click(function() {
 			eval("("+mDialogOkCall+")");
            $('#confirmModal').modal('hide');
            return false;
        });

 		$("#confirmExport").click(function() {
           // $('#exportModal').modal('hide');
	    	onCallBack(mFrameName,mDialogCallback);
        });
 		
 		/* 上一步、下一步 模态框 保存按钮 事件 */
 		$("#btnSave").click(function() {
 			eval("("+mDialogSaveCall+")");
            $('#confirmModal').modal('hide');
            return false;
        });
        
        
   
	},
	/**
	 * 菜单加载
	 */
	menu : function(){
		var _this = this;
		var menuId = parseInt(global.getUrlParam('menuId'));
		var menuCode = "checkManager";	//查岗管理做特殊处理
		//查子菜单
		$.ajax({
			   url: appCtx+"/system/menu/loadSubMenu.html?menuId="+menuId+"&menuCode="+menuCode,
			   type: "GET",
			   dataType: "json",
			   success: function(data) {
				   var len = data.length;
				   if(len > 0){
					   var string = '';
					   var menuIdArray = [];
				   		for(var i=0;i<len;i++){
				   			var da = data[i];
				   			menuIdArray.push(da.functionId);
				   			string+='<li id="menuId_'+da.functionId+'" data-menuId="'+da.functionId+'" data-url="'+da.assemblyName+'"><a class="" href="javascript:;">'+da.functionName+'</a></li>';
				   			if(da.functionId==1605){
				   				data[i].assemblyName=da.assemblyName+'?licence='+licence;
				   			}
				   		}
				   		$('.usermenu').find('ul').html(string);
				   		
				   		//打开点击进来的菜单(如果不存在显示第一个)
//				   		if(menuIdArray.indexOf(menuId) == -1){
//				   			menuId = menuIdArray[0];
//				   		}
				   		if(jQuery.inArray(menuId,menuIdArray) == -1){
				   			menuId = menuIdArray[0];
			   			}
				   		//添加样式
				   		tab.addTab(data,menuId);
				   		$("#menuId_"+menuId).addClass("active");
				   	}
			   }
			})
	}
};

//标题，frame名称，保存执行，回调，页面地址
//window.parent.doDataDialog("update","修改SIM卡",this.name,"saveSimCard()", "querySimCard()",url);
function doDataDialog(OperateType,msg,frameName,btnOkCall,callback,url,funcParam) {
	if(funcParam){
		$.post(url,funcParam,function(data){
			 $("#dataModal .modal-footer").css("display","block");
		       mDialogCallback = callback;
		       mFrameName = frameName;
		       mDialogOkCall = btnOkCall;
			   $("#dataModal .modal-body").html(data);
			   $("#dataModalTitle").html(msg);
		       $("#dataModal").modal();
		       if(OperateType=="detail"){
		    	   $("#dataModal .modal-footer").css("display","none");
		       }
		       //增加funcParam方法,目的将子页面的参数设置到dataModal子元素里去
		       //huangbo 2015-3-18
		       /*if(funcParam){
		       	funcParam();
		       }*/
		       //更改标题中的图片
		       if(OperateType=="update"){
		          //$('#iconEdit').attr('class','iconUpdate');
		       }else{
		    	   //$('#iconEdit').attr('class','iconInsert');
		       } 
			});     
	}else{
		$.post(url,function(data){
			 $("#dataModal .modal-footer").css("display","block");
		       mDialogCallback = callback;
		       mFrameName = frameName;
		       mDialogOkCall = btnOkCall;
			 $("#dataModal .modal-body").html(data);
				$("#dataModalTitle").html(msg);
		       $("#dataModal").modal();
		       if(OperateType=="detail"){
		    	   $("#dataModal .modal-footer").css("display","none");
		       }
		       if(url==appCtx +"/system/common/queryQuestions.html"){
		    	   $('.modal-footer').css('display','none')
		       }
		       //增加funcParam方法,目的将子页面的参数设置到dataModal子元素里去
		       //huangbo 2015-3-18
		       if(funcParam){
		       	//funcParam();
		       }
		       //更改标题中的图片
		       if(OperateType=="update"){
		          //$('#iconEdit').attr('class','iconUpdate');
		       }else{
		    	   //$('#iconEdit').attr('class','iconInsert');
		       } 
			});     
	}
	 
};
function doDataDialogsdoDataDialog(OperateType,msg,frameName,btnOkCall,callback,url,funcParam) {
	if(funcParam){
		$.post(url,funcParam,function(data){
		       mDialogCallback = callback;
		       mFrameName = frameName;
		       mDialogOkCall = btnOkCall;
			   $("#dataModals .modal-body").html(data);
			   $("#dataModalTitles").html(msg);
		       $("#dataModals").modal();
		       
		       //增加funcParam方法,目的将子页面的参数设置到dataModal子元素里去
		       //huangbo 2015-3-18
		       /*if(funcParam){
		       	funcParam();
		       }*/
		       //更改标题中的图片
		       if(OperateType=="update"){
		          //$('#iconEdit').attr('class','iconUpdate');
		       }else{
		    	   //$('#iconEdit').attr('class','iconInsert');
		       } 
			});     
	}else{
		$.post(url,function(data){
		       mDialogCallback = callback;
		       mFrameName = frameName;
		       mDialogOkCall = btnOkCall;
			 $("#dataModals .modal-body").html(data);
				$("#dataModalTitles").html(msg);
		       $("#dataModals").modal();
		       
		       //增加funcParam方法,目的将子页面的参数设置到dataModal子元素里去
		       //huangbo 2015-3-18
		       if(funcParam){
		       	//funcParam();
		       }
		       //更改标题中的图片
		       if(OperateType=="update"){
		          //$('#iconEdit').attr('class','iconUpdate');
		       }else{
		    	   //$('#iconEdit').attr('class','iconInsert');
		       } 
			});     
	}
	 
};
function ajaxLoading(msg,flag,time){
	global.ajaxLoading.pop(msg,flag,time);
}

function showVelidateModal(msg){
	$("#velidateModal").modal('show');
	$("#contentText").html(msg);
}

function closeDataDialog(){
	 $("#dataModal").modal("hide");
}

//confirm
function doConfirm(msg,frameName, callback) {
     mDialogCallback = callback;
     mFrameName = frameName;
     $("#confirmInfo").html(msg);
     $('#confirmModal').modal('show');
 };
 
 //显示导出窗口
 function doExportModal(msg,iFrameName,callback){
	      mFrameName = iFrameName;
	      mDialogCallback = callback;
	    $("#exportTitle").html(msg);
		$("#exportModal").modal('show');
		
	}
 
function onCallBack(mFrameName,mDialogCallback){
	if ("" == mFrameName){
		eval("("+mDialogCallback+")");	
	}else{
		var funStr = "window.frames['"+mFrameName+"']."+mDialogCallback;
		eval("("+funStr+")");	
	}
}



